import { instance } from '@/common/tools/axios';
import { AxiosStandard , LoginStandard } from '@/common/SDK/interface';
import { ElMessage } from 'element-plus';
import { Enum } from '@/common/tools/enum';
class Auth {
    /*请求api*/
    readonly API_REQUEST = {
        //用户登录
       'API_ADMIN_LOGIN' : '/api/admin/login',
    } as any

    public login(callback:any,data:LoginStandard):void{
        instance(<AxiosStandard>{
            url: this.API_REQUEST.API_ADMIN_LOGIN,
            method: 'POST',
            data
        })
        .then((res:any)=>{
            if(res.data.code === Enum.ResCode['ERROR']) {
                const { message } = res.data;
                let info:string;
                if(message.indexOf('username') !== -1) info = '用户名必填';
                else info = '密码必填';
                ElMessage.error(info)
                callback(false)
                return;
            } else if(res.data.code === Enum.ResCode['SUCCESS']){
                callback(res.data)
            }
        })
        .catch((err:any)=>{
            console.error("请求错误：" + err)
            callback(false)
        })
    }
}
export default new Auth();
